//
//  QLMProtectViewController.m
//  Xiaomakuaixiu
//
//  Created by 邬俊涛 on 2018/3/9.
//  Copyright © 2018年 hwd. All rights reserved.
//

#import "QLMProtectViewController.h"
#import "QLMBankInfoInvoiceCell.h"
#import "QLMNorInvoiceTabCell.h"

@interface QLMProtectViewController ()<UITableViewDelegate,UITableViewDataSource>{
    NSArray *tipArray;
    QLMBankInfoInvoiceCell *bankCell;
    QLMInvoiceProModel *aInvoiceProModel;
}

@end

@implementation QLMProtectViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    tipArray=[NSArray arrayWithObjects:@"公司名称：",@"公司税号：",@"注册地址：",@"注册电话：",@"开户银行：",@"银行帐号：", nil];

    CGRect tabFrame = CGRectMake(0, 1, kScreen_width, kScreen_height-41-QLM_StatusBarAndNavigationBarHeight-IOS11_OR_LATER_SPACE(34));
    
    _protableview=[[UITableView alloc] initWithFrame:tabFrame style:UITableViewStyleGrouped];
    _protableview.backgroundColor=[UIColor clearColor];
    _protableview.delegate=self;
    _protableview.dataSource=self;
    _protableview.separatorStyle=UITableViewCellSeparatorStyleNone;
    _protableview.showsVerticalScrollIndicator=NO;
    _protableview.showsHorizontalScrollIndicator=NO;
    _protableview.tableFooterView=[UIView new];
    _protableview.tableHeaderView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_width, 0.0001)];
    [self.view addSubview:_protableview];
    
    if (@available(iOS 11.0, *)) {
        _protableview.contentInsetAdjustmentBehavior=UIScrollViewContentInsetAdjustmentNever;
    } else {
        // Fallback on earlier versions
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)setInvoiceProModel:(QLMInvoiceProModel *)invoiceProModel{
    aInvoiceProModel=invoiceProModel;
    [_protableview reloadData];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
#pragma mark -
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 20;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headerView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_width, 20)];
    headerView.backgroundColor=[UIColor clearColor];

    UIImageView *backView=[[UIImageView alloc] initWithFrame:CGRectMake(20, 9, kScreen_width-40, 11)];
    backView.image=[UIImage imageNamed:@"hts"];
    [headerView addSubview:backView];

    return headerView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 11;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *footerView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_width, 11)];
    footerView.backgroundColor=[UIColor clearColor];

    UIImageView *backView=[[UIImageView alloc] initWithFrame:CGRectMake(20, 0, kScreen_width-40, 11)];
    backView.image=[UIImage imageNamed:@"htx"];
    [footerView addSubview:backView];

    return footerView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row==0||indexPath.row==2||indexPath.row==4) {
        return [bankCell autoChangeHeightWithLabel:bankCell.shuihaoValueLabel]+30;//50;
    }
    return 50;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (aInvoiceProModel.invoiceProArrModel.count==0) {
        return 0;
    }
    return tipArray.count;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return aInvoiceProModel.invoiceProArrModel.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    bankCell=[QLMBankInfoInvoiceCell cellWithTableView:tableView];
    bankCell.selectionStyle=UITableViewCellSelectionStyleNone;
    bankCell.backgroundColor=[UIColor clearColor];
    
    bankCell.suihaoTipLabel.text=[NSString stringWithFormat:@"%@",tipArray[indexPath.row]];

    QLMInvoiceProInfoModel *proInfoModel=[[QLMInvoiceProInfoModel alloc] initWithDictionary:aInvoiceProModel.invoiceProArrModel[indexPath.section] error:nil];
    NSString *string=nil;
    switch (indexPath.row) {
        case 0:
            string=proInfoModel.companyName;
            break;
        case 1:
            string=proInfoModel.taxNo;
            break;
        case 2:
            string=proInfoModel.companyAdd;
            break;
        case 3:
            string=proInfoModel.companyTel;
            break;
        case 4:
            string=proInfoModel.bankName;
            break;
        case 5:
            string=proInfoModel.bankAccount;
            break;
        default:
            break;
    }
    bankCell.shuihaoValueLabel.text=[NSString stringWithFormat:@"%@",string];
    
    return bankCell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

@end
